package com.ajx.cube.common.mvp;



import com.ajx.core.app.Cube;
import com.ajx.core.net.rest.CubeRest;
import com.ajx.core.net.rest.HttpResponse;

import com.ajx.core.net.rest.observer.HttpObservable;

import com.ajx.cube.api.UserSevice;
import com.google.gson.Gson;


import io.reactivex.Observable;
import okhttp3.MediaType;
import okhttp3.RequestBody;

public class UserDataModel extends BaseModel<String> {

    UserSevice service = CubeRest.builder()
            //.baseUrl("https://zhidao.baidu.com/fail/")
            //.addInterceptor(new DebugInterceptor("baidu", R.raw.ok))
            .build()
            .getService(UserSevice.class);


    @Override
    public Observable<String> execute(String action) {
        Observable<HttpResponse> apiObservable = null;
        switch (action) {
            case "login":
                String content = new Gson().toJson(mParams);
                RequestBody requestBody=RequestBody.create(MediaType.parse("application/json; charset=utf-8"),content);
                apiObservable = service.login(requestBody);
                break;
            default:

                break;
        }
        return HttpObservable.getObservable(apiObservable, mLifecycle);
    }
}

